<?php
	include_once('nextVer.php');
?>
<?php
	if($sid == null || $sessionId == null || $pms == null || strcmp(md5($sessionId),substr($pms,3,32))!=0 || $speu == null){
		echo "404";
		return false;
	}
	
	$row = mysql_query("SELECT `sid` , `did` , `sdata` , `start` , `frequence`  FROM `sensordata` where `sid`=".$sid." LIMIT 0,1");
	$res = mysql_fetch_array($row);
	$dataSet = $res['sdata'];
	$dates2 = "";
	$frequence = $res['frequence'];
	$startTime = $res['start'];
	
	for($i=-6;$i<1;$i++){
		$dates[]=date("Y-m-d H:i:s",strtotime($startTime)+$i*$frequence);//"+".($i*$frequence)." seconds",
		$dates2.="'".date("Y-m-d H:i:s",strtotime($startTime)+$i*$frequence)."',";//"+".($i*$frequence)." seconds",
	}
	
	$datas[]=array(
		'name'=>'pH',
		'data'=>$dataSet
	);
	
	
?>
<!DOCTYPE html>
<html lang="zh-CN"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">
	<?php //TODO:change icon ?>
    <link rel="icon" href="./public/pic/pHctrlico.ico">

    <title>show sensor Data</title>

    <!-- Bootstrap core CSS -->
    <link href="../bootstrap/css/bootstrap.css" rel="stylesheet">


	<script src="public/jquery-1.8.2.min.js" type="text/javascript"></script>
    <script src="public/highcharts.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			var options={
								  
								  chart: {
									 renderTo: 'container'
								  },
								  xAxis:{
									categories: [<?php echo rtrim($dates2,",");?>]
								  },
								  yAxis:{
									
								  },
								  legend: {
										layout: 'vertical',
										align: 'right',
										verticalAlign: 'middle',
										borderWidth: 0
								  },
								  series: []
							};
			
			
			var items=<?php echo json_encode($datas)?>;
            $.each(items, function(itemNo, item) {
					var series = {
						data: []
					};
					series.name=item.name;
					var dats=item.data.split(",");
					for(var i=0;i<dats.length;i++)
						series.data.push(parseFloat(dats[i]));
					options.series.push(series);
            });
            
            
			var chart = new Highcharts.Chart(options);
			});
	</script>
    <body>
		<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
		<div class="container">
		<form action="./index.php" method="post">
			<input type="hidden" name="pms" value="<?php echo $pms;?>"/>
			<input type="hidden" name="speu" value="<?php echo specialEncode($uid,$constSalt);?>"/>
			<button class="btn btn-lg btn-info" type="submit">return</button>
		</form>
		</div>
    </body>
</html>